class ReviewsController < ApplicationController
  before_filter :login_required
  def new
    @page_title = I18n.t('review.new_title')
    @review = Review.new
    @photo = Photo.new
    render :action => 'form'
  end
  
  def create
    @page_title = I18n.t('review.new_title')    
    @review = Review.new(:user => current_user)    
    @review.attributes = params[:review] if params[:review]
    @review.save if (success = @review && @review.valid?)
    if success && @place.errors.empty?      
      redirect_to "/" + @review.alias
    else     
      @photo = Photo.new
      render :action => 'form'
    end
  end

def edit    
    @page_title = I18n.t('review.edit_title')
    @review = Human.find(:all, :conditions => ["id = ?", params[:id]])    
    @photo = Photo.new
    if @review.is_rewritable(current_user)
      render :action => 'form'
    else
      redirect_back_or_default('/')
    end
  end

  def update
    @page_title = I18n.t('human.edit_title')    
    @review = Review.find(:all, :conditions => ["id = ?", params[:id]])
    if @review.is_rewritable(current_user)      
      @review.attributes = params[:review]    
      @review.save if (success = @review && @review.valid?)    
      if success && @review.errors.empty?
        redirect_to "/" + @review.alias
      else 
        @photo = Photo.new
        render :action => 'form'
      end
    else
      redirect_to "/" + @review.alias
    end
  end
  
end
